﻿using System;
using System.Data.Objects;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using DAL.Classes;
using DAL.Classes.Repository;
using DAL.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestDAL
{
    [TestClass]
    public class TestEmployeeRepository
    {
        private IRepository<Employee> empRepo;
        private IRepository<Role> roleRepo;
            
        [TestInitialize]
        public void TestInit()
        {
            empRepo = new EmployeesRepository<Employee>();
            roleRepo = new RolesRepository<Role>();
        }

        [TestMethod]
        public void GetNotExistingEmployee()
        {
            var user = empRepo.Get(x => x.Login == "Несуществующий логин" && x.Password == "Несуществующий пароль");
            Assert.IsNull(user);
        }

        [TestMethod]
        public void CreateEmployee()
        {
            Guid guid = Guid.NewGuid();

            var emp = new Employee
                          {
                              Id = guid,
                              FirstName = "Test",
                              LastName = "Test",
                              Login = "Test",
                              Password = "0",
                              Address = "Test",
                              HireDate = DateTime.Now,
                              TerminateDate = DateTime.Now.AddMonths(1),
                              RoleId = roleRepo.Get(x => x.Id == (int)RoleTypes.Administrator).Id
                          };

            empRepo.Add(emp);
            empRepo.Save();

            Employee result = empRepo.Get(item => item.Id == guid);

            Assert.IsNotNull(result);
        }
    }
}
